<template>
  <div class="web-container">
    <span class="router-title">当前位置：<router-link to="/">首页</router-link> > <router-link to="/read">悦读</router-link> > <span class="title">{{$route.query.title||list.main_title}}</span></span>
    <div class="content">
      <div class="content-top">
        <span class="title">{{list.main_title}}</span>
        <div class="desc">
          <span class="author">作者：{{list.author}}</span>
          <span class="time">{{list.publish_time|dataYMD}}</span>
          <span class="readnum">{{collect.readreCount>100?collect.readreCount>100:'100'}}人在读</span>
          <span @click="toggleCollec(collect.whetherCollection)" :class="[collect.whetherCollection==1 ? 'active':'','collec']"><i class="iconfont icon-shoucang"></i>收藏</span>
        </div>
      </div>
      <div class="content-bottom">
        <div class="desc" v-html="list.content">
        </div>
      </div>
    </div>
  </div>
</template>

<script>
import { geReadInfo,readRecord } from "@/api/index";
import { isCollect, addCollect, delCollect } from "@/api/index";
import moment from "moment";
export default {
  data() {
    return {
      articleId: this.$route.query.articleId,
      list: [],
      collect: {}
    };
  },
  components: {},
  created() {
    this.init();
    this.isCollect();
  },
  //时间过滤器
  filters: {
    dataYMD: function(el) {
      return moment(el).format("YYYY-MM-DD hh:mm");
    },
  },
  methods: {
    //阅读记录
    readRecord(){
      readRecord(this.list.main_title,2,this.list.article_id,this.list.content,this.list.cover,this.list.author).then(res=>{
          console.log(res.data)
      })
    },
    //是否收藏 添加 阅读数
    isCollect() {
      if(this.$store.state.isLogin == 0){
         this.$store.commit("SET_LOGINSHOW", true);
         return;
      }
      isCollect(this.$route.query.articleId,2).then(res => {
        console.log(res.data.date);
        this.collect = res.data.date;
      });
    },
     //查询是否收藏
    toggleCollec(is) {
      if (is == 0) {
        addCollect(2,this.list.cover,this.list.main_title,this.list.author,this.list.article_id).then(res => {
          console.log(res.data);
           this.$message({
              message: '收藏成功',
              type: 'success',
              center: true
            });
        });
      } else {
        delCollect(this.collect.collectionId).then(res => {
          console.log(res.data);
           this.$message({
              message: '移除收藏',
              type: 'success',
              center: true
            });
        });
      }
      this.isCollect();
    },
    init() {
      geReadInfo(this.articleId)
        .then(res => {
          let result = res.data.data;
          result.content = result.content.replace(/project_file_root_ue:/g,"http://180.97.46.193/res/file/");
          this.list = result;
          this.list.cover = this.$route.query.cover;
          this.readRecord();
        })
        .catch(err => {});
    }
  }
};
</script>
<style lang="less" scoped>
.router-title {
  display: block;
  font-size: 15px;
  margin: 30px 0;
  .title {
    color: #a1a1a1;
  }
}
.content {
  min-height: 400px;
  background: #fff;
  border-radius: 10px;
  padding: 30px 130px;
  .content-top {
    .title {
      display: block;
      font-size: 36px;
      margin-bottom: 30px;
    }
    .desc {
      display: flex;
      font-size: 16px;
      color: #808080;
      align-items: center;
      span + span {
        margin-left: 40px;
      }
      .collec{
        display: flex;
        align-items: center;
        cursor: pointer;
      }
      .collec.active{
        color: red;
        .iconfont{
          color: red;
        }
      }
      .iconfont{
        font-size: 25px;
      }
    }
  }
  .content-bottom {
    .desc {
      padding-top: 30px;
      padding-bottom: 150px;
      font-size: 17px;
      line-height: 25px;
      text-align: justify;
      color: #252525;
     
    }
  }
}
</style>
<style scoped>
.desc>>>img{
        width: 80% !important;
        height: 90%;
}
</style>

